//
//  settingViewController.m
//  PostMessa
//
//  Created by never down on 15-5-28.
//  Copyright (c) 2015年 ygy_ios. All rights reserved.
//

#import "settingViewController.h"
#import "UIImage+SelfDefined.h"
#import "PostMessa-Prefix.pch"
#import "accountViewController.h"
#import <QuartzCore/CATransaction.h>
@interface settingViewController (){
    UIViewController *viewController;
    NSArray *titleArr;

}

@end

@implementation settingViewController

-(instancetype)init{
    return [self initWithViewController:nil];
}

- (instancetype)initWithViewController:(UIViewController *)_viewController {
    self = [super init];
    viewController = _viewController;
    return self;
}
#define LABELMARGINRIGHT 10.0f
#define BORDERWIDTH 0.5f
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:ERHUOGREY(233)];

    //创建导航栏
    UIView *nav = [[UIView alloc] initWithFrame:CGRectMake(-BORDERWIDTH, -BORDERWIDTH, WIDTH , STATUSHEIGHT + NAVBARHEIGHT)];
    
    [nav setBackgroundColor:[UIColor whiteColor]];
    [nav.layer setBorderColor:[ERHUORED(1.0f) CGColor]];
    [nav.layer setBorderWidth:0.5f];
    nav.clipsToBounds = YES;
    [self.view addSubview:nav];
    
    //左侧返回按钮
    UIImage *img = [UIImage imageNamed:@"arrow-back.png"];
//    NSURL *url = [NSURL URLWithString:@"http://img3.douban.com/icon/g12570-3.jpg"];
//    UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
    UIButton *backB = [[UIButton alloc] initWithFrame:CGRectMake(LABELMARGINRIGHT, STATUSHEIGHT, img.size.width + LABELMARGINRIGHT * 2, NAVBARHEIGHT)];
    [backB setImage:img forState:UIControlStateNormal];
    [backB setImageEdgeInsets:UIEdgeInsetsMake((STATUSHEIGHT - img.size.height) / 2,LABELMARGINRIGHT ,(STATUSHEIGHT - img.size.height) / 2, LABELMARGINRIGHT)];
//    backB.backgroundColor = ERHUORED(1.0f);
    
    [backB addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [nav addSubview:backB];
    
    //标题
    UILabel *titleL = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width / 4, STATUSHEIGHT, self.view.bounds.size.width / 2, NAVBARHEIGHT)];
    [titleL setText:SETTING];
    [titleL setTextAlignment:NSTextAlignmentCenter];
    [titleL setTextColor:ERHUORED(1.0f)];
    [titleL setFont:[UIFont systemFontOfSize:CONTENTFONTSIZE]];
    [nav addSubview:titleL];
    
    //
    titleArr = [NSArray arrayWithObjects:@"帐号信息", @"修改密码", @"意见反馈", @"关于我们", @"推荐给朋友", nil];
    UIView *contentView  = [[UIView alloc] initWithFrame:CGRectMake(0, NAVHEIGHT + CELLMARGIN, WIDTH, self.view.frame.size.height - (NAVHEIGHT + CELLMARGIN))];
    [self.view addSubview:contentView];
    
    NSUInteger index = 0;
    for(NSString * obj in titleArr){
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, BUTTONHEIGHT * index, WIDTH, BUTTONHEIGHT)];
        [btn setBackgroundColor:[UIColor whiteColor]];
        
        if(index < titleArr.count - 1 ){
            //online_device_web.png
            UIImage *img  = [UIImage  imageNamed:@"online_device_web.png"];
            [btn setImageEdgeInsets:UIEdgeInsetsMake((BUTTONHEIGHT - img.size.height)/2, WIDTH - LABELMARGINRIGHT - img.size.width , (BUTTONHEIGHT - img.size.height)/2,LABELMARGINRIGHT )];
            [btn setImage:img forState:UIControlStateNormal];
            [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 32.0 - img.size.width,0 ,0 )];
        }else{
            [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 32.0, 0, 0)];

        }
        [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
        [btn setTitle:obj forState:UIControlStateNormal];
        [btn setTitleColor:ERHUOTEXT forState:UIControlStateNormal];
        [btn.titleLabel setFont:[UIFont systemFontOfSize:CONTENTFONTSIZE]];
        SEL sel = nil;
        switch (index) {
            case 0:
                sel = @selector(acount);
                break;
            case 1:
                sel = @selector(pass);
                break;
            case 2:
                sel = @selector(acount);
                break;
            case 3:
                sel = @selector(acount);
                break;
            case 4:
                sel = @selector(acount);
                break;
            default:
                break;
        }
        [btn addTarget:self action:sel forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:btn];
        if(index < titleArr.count - 1){
            UIView *split = [[UIView alloc] initWithFrame:CGRectMake(CELLMARGIN * 2, btn.frame.size.height - BORDERWIDTH, btn.frame.size.width - CELLMARGIN * 4, BORDERWIDTH)];
            [split setBackgroundColor:ERHUORED(0.5f)];
            [btn addSubview:split];
        }
        
        index++;
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


- (void)back{
//    [self dismissViewControllerAnimated:YES completion:nil];
    CATransition * transition = [CATransition animation];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromRight;
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    [self.navigationController popViewControllerAnimated:NO];

}

- (void)acount{
    accountViewController *accountVC = [[accountViewController alloc] init];
    [self.navigationController pushViewController:accountVC animated:YES];
}

- (void)pass{
    
}

@end
